<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
<meta content="yes" name="apple-mobile-web-app-capable">
<meta content="black" name="apple-mobile-web-app-status-bar-style">
<meta content="telephone=no" name="format-detection">
<link rel="stylesheet" href="../static/bootstrap/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/bootstrap/easyui.css">
<link rel="stylesheet" type="text/css" href="../static/easyui/themes/icon.css">
<link rel="stylesheet" href="../static/metisMenu/metisMenu_custom.css" />
<link rel="stylesheet" href="../static/css/style-app.css" />
<script src="../static/jquery/jquery-1.12.4.js"></script>
<script src="../static/easyui/jquery.easyui.min.js"></script>
<script src="../static/easyui/locale/easyui-lang-zh_CN.js"></script>
<script src="../static/jqueryValidate/jquery.validate.min.js"></script>
<script src="../static/jqueryValidate/additional-methods.min.js"></script>
<script src="../static/jqueryValidate/localization/messages_zh.min.js"></script>
<script src="../static/moment/moment.js"></script>
<script src="../static/moment/locale/zh-cn.js"></script>
<title>预算审核</title>
</head>
<style>.tabs-container+.table-container {
    top: 83px;
}</style>
<body
	<div class="top-part">
		<div class="header">
			<div class="return">
				<a href="javascript:history.go(-1);"></a>
			</div>
			<div class="header-title">预算审核列表</div>
		</div>

	</div>
	<div class="tabs-container">
		<div class="tabs-define">
			<div id="todo" class="active">未审核</div>
			<div id="completed">已审核</div>
		</div>
	</div>
	<div class="table-container" data-options="region:'center'"></div>
	<div id="pro_tb">
		<div class="summoney">
			已通过审核总金额：<font color="red" id="summoney"></font>
		</div>
	</div>
</body>
<script th:inline="javascript">
	var currentPro;
	var projectitemid = [[${projectitemid}]];
	$(document).ready(function() {
		unreviewed();
		$("#todo").click(function(){
			$(this).siblings().removeClass("active");
			$(this).addClass("active");
			unreviewed();
			})
			$("#completed").click(function(){
				$(this).siblings().removeClass("active");
				$(this).addClass("active");
				reviewed();
			})
			summoney();
	});
	function reviewed() {
		$('.table-container').html('<div><table id="reviewed_table" class="easyui-datagrid" style="display:none;min-height: 100%"></table></div>');
		$('#reviewed_table').datagrid({
			rownumbers : false,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : false,
			striped : true,
			//title:'已审核',
			toolbar : '#pro_tb',
			url : "../reviewed/budgetsubitem.do",
			method : 'get',
			queryParams : {
				projectitemid:projectitemid
			},
			columns : [ [ {
				field : 'title',
				title : '预算类别',
				width : '100%',
				formatter : function(value,row,index) {
					var html='';
					html+= '<div class="info-unreviewed">'
					if(row.item){
						html+= '<div class="info-item-name" style="width:'+ ellipsis(0) +'px;">'+ row.item.content +'</div>'
					}else{
						html+= '<div class="info-item-name" style="width:'+ ellipsis(0) +'px;">'+ value +'</div>'
					}
					html+= '<div class="info-content" style="width:'+ ellipsis(0) +'px;">'+ row.content +'</div>';
					html+= '<div class="info-money">￥'+ row.money +'</div>';
					if (row.status == 4){
						html += '<div class="info-status ok">已审</div>';
					}
					if (row.status == 3){
						html += '<div class="info-status refuse">已拒绝</div>';
					}
					if (row.status == 6){
						html += '<div class="info-status two">待二级审核</div>';
					}
					if (row.status == 7){
						html += '<div class="info-status one">待一级审核</div>';
					}
					html += '</div>';
					return html;
				}
			} ] ]
		});
	}
	function unreviewed(){
		$('.table-container').html('<div><table id="unreviewed_table" class="easyui-datagrid" style="display:none;min-height: 100%"></table></div>');
		$('#unreviewed_table').datagrid({
			rownumbers : false,
			singleSelect : true,
			pagination : true,
			fitColumns : false,
			border : true,
			striped : true,
			singleSelect: true,
			//title:'未审核',
			url : "../review/budgetsubitem.do",
			method : 'get',
			onClickCell: onClickCell,
			queryParams : {
				projectitemid:projectitemid
			},
			columns : [ [ {
				field : 'title',
				title : '预算类别',
				width : '100%',
				formatter : function(value,row,index) {
					var html='';
					html+= '<div class="info-unreviewed">'
						if(row.item){
							html+= '<div class="info-item-name" style="width:'+ ellipsis(0) +'px;">'+ row.item.content +'</div>'
						}
						html+= '<div class="info-content" style="width:'+ ellipsis(0) +'px;">'+ row.content +'</div>';
					html+= '<div class="info-money">￥'+ row.money +'</div>';
					html+='<div class="info-handle"><a class="btn-yellow" onclick="updatepro('+index+')">审核</a></div>'
					html+='</div>'
					return html;
				}
			} ] ]
		});
	}
	function ellipsis(value){
		var WIDTH = $("body").width();
		WIDTH-=10;
		var width;
		width = WIDTH-value
		return width;
	}
	function updatepro(index) {
		var item = $("#unreviewed_table").datagrid('getRows')[index];
		window.location.href = "../appunreviewedadd/budgetmain.do?id=" + item.id;
	}

	function refreshProTable() {
		$('#reviewed_table').datagrid("load",{
			projectitemid:projectitemid
		});
		$('#unreviewed_table').datagrid("load",{
			projectitemid:projectitemid
		});
		summoney();
	}
	
	$.extend($.fn.textbox.defaults.rules, {
	     number: {//value值为文本框中的值
	           validator: function (value) {
	          var reg = /^\d+(\.\d+)?$/;
	           return reg.test(value);
	       },
     message : "请输入数字"
 		}
 	});
	
	$.extend($.fn.datagrid.methods, {
		editCell: function(jq,param){
			return jq.each(function(){
				var opts = $(this).datagrid('options');
				var fields = $(this).datagrid('getColumnFields',true).concat($(this).datagrid('getColumnFields'));
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor1 = col.editor;
					if (fields[i] != param.field){
						col.editor = null;
					}
				}
				$(this).datagrid('beginEdit', param.index);
				for(var i=0; i<fields.length; i++){
					var col = $(this).datagrid('getColumnOption', fields[i]);
					col.editor = col.editor1;
				}
			});
		}
	});
	
	var editIndex = undefined;
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#unreviewed_table').datagrid('validateRow', editIndex)){
			$('#unreviewed_table').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	}
	function onClickCell(index, field){
		if (endEditing()){
			$('#unreviewed_table').datagrid('selectRow', index)
					.datagrid('editCell', {index:index,field:field});
			editIndex = index;
		}
	}
	function summoney(){
		$.ajax({
			type : 'GET',
			url : "../reviewed/budgetsubitem.do",
			data:{projectitemid:projectitemid},
			contentType : "application/json",
			success : function(data) {
				var sum = 0;
				$.each(data.rows, function(i,row){      
					sum+= parseFloat(row.money);
				 }); 
				$("#summoney").text(sum.toFixed(2));
			},
			dataType : "json"
		});
	}
</script>
</html>